SET EXCL OFF
SET SAFE OFF
CLEA
DR='N:'
F1='PUR_DRUG'
F2='PUR_DISP'
F3='PUR_TEMP'
F4='SUPPLIER'
F5='DRUGS'
F6='DISPOS'
DO ADDRESSC
SAVE SCREEN vscreen
SET COLO TO W+/GR
@ 12,30 CLEA TO 14,50
@ 12,30 TO 14,50
@ 13,31 SAY 'PO.No. FROM :       TO'
STORE 0 TO vpo1,vpo2
@ 13,45 GET vpo1 PICT '99999'
@ 13,54 GET vpo2 PICT '99999'
READ
IF vpo2 = 0
   REST SCREEN FROM vscreen
   RETURN
ELSE
   USE &DR&F1
   COPY STRU TO &DR&F3
   USE &DR&F3 EXCL
   APPE FROM &DR&F1 FOR order_nber >= vpo1 .AND. oerder_nber <= vpo2 .AND. ordr_print # .T.
   APPE FROM &DR&F2 FOR order_nber >= vpo1 .AND. oerder_nber <= vpo2 .AND. ordr_print # .T.
   INDE ON order_nber TO &DR&F3
   UNLOCK
   SET EXCL OFF
   USE &DR&F3 INDE &DR&F3
   GO TOP
ENDIF
VCODE_SUPP=SUPP_CODE
VPRNUM=VPO1
STORE 0 TO vno,VTTL
VREC=1
VULANG = .T.
DO WHILE VULANG
   USE &DR&F4
   LOCA FOR SUPP_CODE = VCODE_SUPP
   VNAME=SUPP_NAME
   VADD1=SUPP_ADD1
   VADD2=SUPP_ADD2
   VCITY=SUPP_CITY
   VTEL1=SUPP_TEL1
   VTEL2=SUPP_TEL2
   VFAXC=SUPP_FAX
   VTELX=SUPP_TELEX
   @  1, 00 SAY AEANAME
   @  5, 24 SAY CHR(14)+'P U R C H A S E  O R D E R'
   @  6, 24 SAY CHR(14)+'--------------------------'
   @  7, 28 SAY 'PURCHASE ORDER NO. : '+LTRIM(STR(INT(VPRNUM)))
   @  7, 58 say 'DATE : '+DTOC(DATE())
   @  9,  0 SAY 'SUPPLIER : '+VNAME
   @ 10,  0 SAY "ADDRESS  : "+VADD1
   @ 11, 12 SAY VADD2
   @ 11, 64 SAY "CITY  : "+VCITY
   @ 12,  0 SAY "Telephone : "+VTEL1+','+VTEL2
   @ 12, 30 SAY "Fax  : "+VFAXC
   @ 12, 64 SAY "Telex : "+VTELX
   @ 13,  0 say repl('=',102)
   @ 14,  0 SAY 'NO'
   @ 14,  6 say 'PRODUCT'
   @ 14, 28 SAY 'TYPE'
   @ 14, 41 say 'UNIT'
   @ 14, 51 SAY 'PACKAGING'
   @ 14, 62 SAY ' QTY.'
   @ 14, 68 SAY 'UNIT PRICE'
   @ 14, 81 SAY " DISC"
   @ 14, 90 SAY "TOTAL PRICE"
   @ 15,0 say repl('-',102)
   USE &DR&F3
   GO VREC
   STORE 16 TO VROW
   DO WHILE VROW < 46
      vno = vno + 1
      @ BR,  0 SAY vno PICT '999'
      @ BR,  6 SAY DRUG_NAME
      @ BR, 28 SAY DRUG_TYPE
      @ BR, 41 SAY DRUG_QANT+" "+DRUG_UNIT
      @ BR, 51 SAY ALLTRIM(SUBS(BUY_UNIT,1,9))+' '+ALLTRIM(BSEL)
      @ BR, 62 SAY QANT_PURCH PICT '9,999'
      IF AEADECI
         @ BR, 67 SAY U_PR_PURCH PICT '99,999,999.99'
      ELSE
         @ BR, 68 SAY U_PR_PURCH PICT '99,999,999'
      ENDIF
      IF DISC_PURCH<>0
         @ BR, 81 SAY DISC_PURCH PICT "99.9"
         @ BR, 85 SAY "%"
      ENDIF
      IF AEADECI
         @ BR,89  SAY NET_PURCH PICT "99,999,999.99"
      ELSE
         @ BR,90  SAY NET_PURCH PICT "99,999,999"
      ENDIF
      VTTL=VTTL+NET_PURCH
      VROW = VROW + 1
      SKIP +1
      IF VROW > 45
         EXIT
      ENDIF
      IF EOF()
         VULANG = .F.
         EXIT
      ENDIF
      IF ORDER_NBER#VPRNUM
         VREC=RECNO()
         VPRNUM=ORDER_NBER
         VULANG = .T.
         EXIT
      ELSE
         LOOP
      ENDIF
   ENDDO






PR=0
USE &DR&F4
LOCA FOR ORDER_N_Y_P = .T. .AND. .NOT. EOF()
WFLAG=0
DO WHILE .T.
   IF FOUND()
      WFLAG=1
      PR=PR+1
      IF PR=1
         @  5,  3  TO  7, 31    DOUBLE
         @  6,  5  SAY "PRINT PURCHASE ORDER FORM"
         KLR='N'
         DO SET_DEV
         IF KLR='Y'
            CLOSE DATA
            CLOSE INDEX
            RETURN
         ENDIF
      ENDIF
      SUPPCOD=SUPP_CODE
      SUPPCUR=SUPP_CURR
      DO CASE
      CASE SUPPCUR='IDR'
         WCUR='RUPIAH'
         KOMA=.F.
      CASE SUPPCUR='USD' .OR. SUPPCUR='SGD' .OR. SUPPCUR='AUD'
         WCUR='DOLLAR'
         KOMA=.T.
      CASE SUPPCUR='JPY'
         WCUR='YEN'
         KOMA=.T.
      CASE SUPPCUR='FFR'
         WCUR='FRANC'
         KOMA=.T.
      CASE SUPPCUR='GBP'
         WCUR='POUNDSTERLING'
         KOMA=.T.
      ENDCASE
      SUPPNAM=SUPP_NAME
      SUPPADD1=SUPP_ADD1
      SUPPADD2=SUPP_ADD2
      SUPPCITY=SUPP_CITY
      SUPPCOUNT=SUPP_COUNT
      SUPPTEL=SUPP_TEL1
      SUPPFAX=SUPP_FAX
      SUPPTELEX=SUPP_TELEX
      CONPER=CONTACT_P
      MPPN=PPN
      PAYTERM=TERM_PAYMT
      store 0 to ttl1,ttl2,ttl3,ttl4,ttl5
      set devi to print
      @ 0,0 say chr(18) pict 'x'
      @ 0,0 SAY CHR(27)+CHR(77)
      ULANG='N'
      CNT=0
      TTL=0
      BR=0
      ITM=0
      DO WHILE CNT<=1
         CNT=CNT+1
         @  1, 00 SAY AEANAME
         @  5, 24 SAY CHR(14)+'P U R C H A S E  O R D E R'
         @  6, 24 SAY CHR(14)+'--------------------------'
         @  7, 28 SAY 'PURCHASE ORDER NO. : '+LTRIM(STR(INT(PRNUM)))
         @  7, 58 say 'DATE : '+DTOC(DATE())
         @  9,  0 SAY 'SUPPLIER : '+SUPPNAM
         @ 10,  0 SAY "ADDRESS  : "+SUPPADD1
         @ 11, 12 SAY SUPPADD2
         @ 11, 64 SAY "CITY  : "+SUPPCITY
         @ 12,  0 SAY "Telephone : "+SUPPTEL
         @ 12, 30 SAY "Fax  : "+SUPPFAX
         @ 12, 64 SAY "Telex : "+SUPPTELEX
         @ 13,  0 say repl('=',102)
         @ 14,  0 SAY 'NO'
         @ 14,  6 say 'PRODUCT'
         @ 14, 28 SAY 'TYPE'
         @ 14, 41 say 'UNIT'
         @ 14, 51 SAY 'PACKAGING'
         @ 14, 62 SAY ' QTY.'
         @ 14, 68 SAY 'UNIT PRICE'
         @ 14, 81 SAY " DISC"
         @ 14, 90 SAY "TOTAL PRICE"
         @ 15,0 say repl('-',102)
         BR=15
         USE &DR&F3
         GO TOP
         LOCATE FOR SUPP_CODE=SUPPCOD .AND. .NOT. ORDR_PRINT .AND. .NOT. EOF()
         DO WHILE .T.
            IF FOUND()
               br=br+1
               ITM=ITM+1
               IF CNT=1
                if rec_lock(0)
                   REPL ORDR_PRINT WITH .T.
                endif
                unlock
               ENDIF
               IF ITM>=31
                  ULANG='Y'
                  EXIT
               ENDIF
               DRCD=DRUG_CODE
               qty =qant_purch
               USE &DR&F5 INDE &DR&F5
               SEEK DRCD
               BSEL=STR(BUY_SELL_R,4)
               if rec_lock()
                  repl st_on_orde with st_on_orde+(qty*buy_sell_r)
               endif
               unlock
               USE &DR&F3
               @ BR,  1 SAY STR(INT(ITM),2)
               @ BR,  6 SAY DRUG_NAME
               @ BR, 28 SAY DRUG_TYPE
               @ BR, 41 SAY DRUG_QANT+" "+DRUG_UNIT
               @ BR, 51 SAY ALLTRIM(SUBS(BUY_UNIT,1,9))+' '+ALLTRIM(BSEL)
               @ BR, 62 SAY QANT_PURCH PICT '9,999'
               IF AEADECI
                  @ BR, 67 SAY U_PR_PURCH PICT '99,999,999.99'
               ELSE
                  @ BR, 68 SAY U_PR_PURCH PICT '99,999,999'
               ENDIF
               IF DISC_PURCH<>0
                  @ BR, 81 SAY DISC_PURCH PICT "99.9"
                  @ BR, 85 SAY "%"
               ENDIF

               IF AEADECI
                  @ BR,89  SAY NET_PURCH PICT "99,999,999.99"
               ELSE
                  @ BR,90  SAY NET_PURCH PICT "99,999,999"
               ENDIF

               TTL=TTL+NET_PURCH
*              BR=BR+1
               CONTINUE
               LOOP
            ELSE
               EXIT
            ENDIF
         ENDDO
         USE &DR&F3
         GO TOP
         LOCATE FOR SUPP_CODE=SUPPCOD .AND. ORDER_NBER=0  .AND. .NOT. EOF()
         DO WHILE .T.
            IF FOUND()
               br=br+1
               ITM=ITM+1
               IF CNT=1
                if rec_lock(0)
                   REPL ORDR_PRINT WITH .T.
*                   REPL ORDER_NBER WITH PRNUM
*                   REPL DATE_PURCH WITH DATE()
                endif
                unlock
               ENDIF
               IF ITM>=31
                  ULANG='Y'
                  EXIT
               ENDIF
               DSCD=DISP_CODE
               qty =qant_purch
               USE &DR&F6 INDE &DR&F6
               SEEK DSCD
               BSEL=STR(BUY_SELL_R,4)
               if rec_lock()
                  repl st_on_orde with st_on_orde+(qty*buy_sell_r)
               endif
               unlock
               USE &DR&F3

               @ BR,  1 SAY STR(INT(ITM),2)
               @ BR,  6 SAY DISP_NAME
               @ BR, 28 SAY DISP_TYPE
               @ BR, 41 SAY DISP_QANT+" "+DISP_UNIT
               @ BR, 51 SAY ALLTRIM(SUBS(BUY_UNIT,1,9))+' '+ALLTRIM(BSEL)
               @ BR, 62 SAY QANT_PURCH PICT '9,999'

*****          @ BR, 67 SAY U_PR_PURCH PICT '99,999,999.99'

               IF KOMA
                  @ BR, 67 SAY U_PR_PURCH PICT '99,999,999.99'
               ELSE
                  @ BR, 68 SAY U_PR_PURCH PICT '99,999,999'
               ENDIF


*               @ BR, 77 SAY VALU_PURCH PICT '9,999,999'
               IF DISC_PURCH<>0
                  @ BR, 81 SAY DISC_PURCH PICT "99.9"
                  @ BR, 85 SAY "%"
               ENDIF

*****               @ BR,89  SAY NET_PURCH PICT "99,999,999.99"
               IF KOMA
                  @ BR,89  SAY NET_PURCH PICT "99,999,999.99"
               ELSE
                  @ BR,90  SAY NET_PURCH PICT "99,999,999"
               ENDIF

               TTL=TTL+NET_PURCH
*              BR=BR+1
               CONTINUE
               LOOP
            ELSE
               EXIT
            ENDIF
         ENDDO
         IF TTL<>0
            @ 46, 00 SAY REPL('-',102)
            IF MPPN=.T.
               @ 47, 61 SAY "VALUE BEFORE TAX    : "+SUPPCUR

*               @ 47, 88 SAY TTL PICT '999,999,999.99'
               IF KOMA
                  do secnil with 47,88,ttl
               ELSE
                  do secnilRP with 47,89,ttl
               ENDIF

               @ 48, 61 SAY "P.P.N.  10 %        : "+SUPPCUR
               VALPPN=10/100*TTL
               GRNTTL=TTL+VALPPN

*               @ 48, 88 SAY VALPPN PICT '999,999,999.99'
                IF KOMA
                   do secnil1 with 48,88,valppn
                ELSE
                   do secnil1R with 48,89,valppn
                ENDIF


               I=0
               X=1
               SX=0
               BARI=48
               Declare ARRAY1[3]
               HARGA=NTOS2(GRNTTL,WCUR,'CENT')
               S_PARSE(HARGA,3,50,ARRAY1)
               DO WHILE X<=I
                  @ BARI,1 SAY ARRAY1[X]
                  IF BARI=49
                     SX=1
                     @ 49, 88 SAY '-------------'
                  ENDIF
                  X=X+1
                  bari=bari+1
               ENDDO


               IF SX=0
                  @ 49, 88 SAY '-------------'
               ENDIF

               @ 50, 61 say 'TOTAL VALUE OF P.O. : '+SUPPCUR

*               @ 50, 88 SAY GRNTTL PICT '999,999,999.99'
                IF KOMA
                   do secnil1 with 50,88,grnttl
                ELSE
                   do secnil1R with 50,89,grnttl
                ENDIF

            ELSE
               @ 47, 61 say 'TOTAL VALUE OF P.O. : '+SUPPCUR

*               @ 47, 88 SAY TTL PICT '999,999,999.99'
               IF KOMA
                  do secnil with 47,88,ttl
               ELSE
                  do secnilRP with 47,89,ttl
               ENDIF


               I=0
               X=1
               BARI=48
               Declare ARRAY1[3]
               HARGA=NTOS2(TTL,WCUR,'CENT')
               S_PARSE(HARGA,3,50,ARRAY1)
               DO WHILE X<=I
                  @ BARI,1 SAY ARRAY1[X]
                  X=X+1
                  bari=bari+1
               ENDDO

            ENDIF

            TTL=0
            @ 51,  0 SAY REPL('-',102)
            @ 53,  0 SAY "PAYMENT DUE "+LTRIM(STR(PAYTERM,3))+" DAYS AFTER COMPLETE DELIVERY AND SUBMISSION OF INVOICE"
            @ 53, 75 SAY "AUTHORIZED SIGNATURE :"
            IF MPPN=.T.
               @ 54, 0 SAY "NO PAYMENT WILL BE PROCESSED BEFORE SUBMISSION OF FAKTUR PAJAK"
            ENDIF
            @ 55,  0 SAY "COPY OF THIS PURCHASE ORDER SHOULD BE PRESENTED AT TIME OF DELIVERY"
            @ 59, 75 SAY "____________________ "
*            DO CASE
*               CASE CNT=3
*                  KETE = "SUPPLIER"
*               CASE CNT=2
*                  KETE = "PURCHASING"
*               CASE CNT=1
*                  KETE = "ACCOUNTING"
*            ENDCASE
*            @ 60,  0 SAY "COPY # "+STR(INT(CNT),1)+" FOR "+KETE
            @ 60,  0 SAY "COPY #1 FOR SUPPLIER ;  #2 FOR PURCHASING ;  #3 FOR ACCOUNTING"
            ITM=0
         ENDIF
         IF CNT=1
            EXIT
         ENDIF

         EJECT

*         BR=100
*         EJECT
*         @ 0,0 SAY CHR(18) PICT 'X'
*         EXIT
      ENDDO
      SELE 1
      IF ULANG='N'
       if rec_lock(0)
          REPL ORDR_N_Y_P WITH .F.
       endif
       unlock
       CONT
      ELSE
       LOCATE FOR ORDR_N_Y_P=.T.  .AND. .NOT. EOF()
      ENDIF
      LOOP
   ELSE
      IF WFLAG=1
         EJECT
         @ 0,0 SAY CHR(18) PICT 'X'
      ENDI
      SET DEVI TO SCREEN
      CLOSE DATA
      CLOSE INDEX
      RETURN
   ENDIF
ENDDO


